package nc.impl.cad.compcal;

import java.util.ArrayList;
import java.util.HashMap;

import nc.bs.dao.BaseDAO;
import nc.itf.cad.compcal.ITFCompcal;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.vo.cad.calmigr.CalMigrmatrixVO;
import nc.vo.cad.calscroll.CalScrollmatrixVO;
import nc.vo.pub.BusinessException;

public class CompcalImpl implements ITFCompcal{

	private BaseDAO superdmo;
	
	public HashMap getMigrmatrixbs(CalMigrmatrixVO[] calMigrmatrixVOs) throws BusinessException {
		HashMap<String,ArrayList> map = new HashMap<String,ArrayList>();
		String pk_migrmatrix = "";
		for(int i=0; i<calMigrmatrixVOs.length; i++){
			pk_migrmatrix = calMigrmatrixVOs[i].getPk_migrmatrix();
			String sql = "select a.pk_migrmatrix, b.degreename, b.degreenum,b.isbadloan,a.migramount,a.migrrate,a.lossrate " +
				"from cad_cal_migrmatrix_b a, caa_doc_degree b " +
				"where a.pk_migrmatrix='" + pk_migrmatrix + "' " +
				"and a.pk_degree = b.pk_degree and isnull(a.dr,0)=0 and isnull(b.dr,0)=0 " +
				"order by b.degreenum";
			ArrayList result = (ArrayList)getBaseDAO().executeQuery(sql, new MapListProcessor());
			map.put(pk_migrmatrix, result);
		}
		return map;
	}

	public HashMap getScrollmatrixbs(CalScrollmatrixVO[] calScrollmatrixVOs) throws BusinessException {
		HashMap<String,ArrayList> map = new HashMap<String,ArrayList>();
		String pk_scrollmatrix = "";
		for(int i=0; i<calScrollmatrixVOs.length; i++){
			pk_scrollmatrix = calScrollmatrixVOs[i].getPk_scrollmatrix();
//			String sql = "select b.pk_losscalscrmodel, b.latelevel, a.scrollamount, a.scrollrate,a.lossrate " +
//				"from cad_cal_scrollmatrix_b a, cad_pub_losscalscrmodel b " +
//				"where a.pk_scrollmatrix='" + pk_scrollmatrix + "' " +
//				"and a.pk_losscalscrmodel = b.pk_losscalscrmodel and isnull(a.dr,0)=0 and isnull(b.dr,0)=0 " +
//				"order by b.orderid";
			String sql = "select a.scrolldate, a.scrollamount, a.scrollrate " +
				"from cad_cal_scrollmatrix_b a " +
				"where a.pk_scrollmatrix='" + pk_scrollmatrix + "' " +
				"and isnull(a.dr,0)=0 " +
				"order by a.scrolldate";
			ArrayList result = (ArrayList)getBaseDAO().executeQuery(sql, new MapListProcessor());
			map.put(pk_scrollmatrix, result);
		}
		return map;
	}

	private BaseDAO getBaseDAO() {
		if(superdmo==null)
			superdmo=new BaseDAO();
		return superdmo;
	}
}
